package com.ywgt.blockingqueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class SynchronousQueueTest {
    public static void main(String[] args) {
        BlockingQueue blockingQueue=new SynchronousQueue<>();

        new Thread(()->{
            try {
                System.out.println("put"+Thread.currentThread().getName()+"1");
                blockingQueue.put("1");
                System.out.println("put"+Thread.currentThread().getName()+"2");
                blockingQueue.put("2");
                System.out.println("put"+Thread.currentThread().getName()+"3");
                blockingQueue.put("3");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"T1").start();
        new Thread(()->{
            try {
                System.out.println(blockingQueue.take());
                System.out.println(blockingQueue.take());
                System.out.println(blockingQueue.take());
            } catch (Exception e) {
                e.printStackTrace();
            }
        },"T2").start();
    }
}
